package com.djinfo.work.service.impl;

import com.djinfo.work.entity.TbDicFileMd5;
import com.djinfo.work.service.TbDicFileMd5Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.djinfo.work.dao.TbDicFileMd5Dao;
import com.djinfo.work.entity.TbDicFileMd5;
import com.djinfo.work.service.TbDicFileMd5Service;

import java.io.File;

/**
 * Created by Administrator on 2016/10/27.
 */
@Service("tbDicFileMd5Service")
public class TbDicFileMd5DServiceImpl implements TbDicFileMd5Service {
    @Autowired
    private TbDicFileMd5Dao dao;
    @Override
    public void save(String md5, String path) {
        TbDicFileMd5 tbDicFileMd5=new TbDicFileMd5();
        tbDicFileMd5.setMd5(md5);
        tbDicFileMd5.setFilePath(path);
        dao.save(tbDicFileMd5);
    }

    @Override
    public String getTbDicFileMd5(String md5, String path) {
        TbDicFileMd5 tbDicFileMd5=  dao.getTbDicFileMd5(md5);
        String Newpath="";
        if(tbDicFileMd5!=null){
        	//获取存已经在数据库的路径
        	Newpath=tbDicFileMd5.getFilePath();
        }
        return Newpath;
    }
    
    
    //删除文件
    public boolean deleteFile(String path) {
    	File file= new File("d:/upload/"+path);
    	
    	//文件是否存在
    	if(file.exists()){
    		
    		boolean dOrf= file.delete();
    		System.out.println("路径不对吗？  d:/upload/"+path);
    		  return dOrf;
    	}
        return false;
    }
}
